import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { resolve } from 'path'

// https://vite.dev/config/
export default defineConfig({
  css: {
    preprocessorOptions: {
      less: {
        // 这里可以添加全局的 Less 变量或 mixin
        // additionalData: `@import "@/assets/less/index.less";`,
        javascriptEnabled: true,
      }
    }
  },
  plugins: [
    vue({
      script: { globalTypeFiles: ['./src/types/global.d.ts'] }
    }),
    // unplugin-auto-import 配置
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        'pinia'
      ],
      resolvers: [
        ElementPlusResolver()
      ],
      dts: 'src/types/auto-import.d.ts'
    }),
    // unplugin-vue-components 配置
    Components({
      resolvers: [
        ElementPlusResolver({
          importStyle: 'sass',
          directives: true,
          // importIcons: true,
        })
      ],
      dirs: ['src/components'],
      dts: 'src/types/auto-components.d.ts'
    }),
  ],
  resolve: {
    alias: {
      '@': resolve(__dirname, './src')
    }
  },
  esbuild: {
    target: 'es2020' // 确保目标版本足够新
  }
  // server: {
  //   port: 3000,
  //   open: true,
  //   proxy: {
  //     '/api': {
  //       // target: 'http://8.130.120.222:1800/',
  //       target: 'http://localhost:1800/',
  //       changeOrigin: true,
  //       rewrite: (path) => path.replace(/^\/api/, '')
  //     }
  //   }
  // },
})
